package com.base.common.action;

import static com.base.common.GlobaConstants.ACTION_RESULT_DATA;
import static com.base.common.GlobaConstants.ASYNCHRONOUS;
import static com.base.common.GlobaConstants.CONTENT_TYPE;
import static com.base.common.GlobaConstants.CONTENT_TYPE_HTML;
import static com.base.common.GlobaConstants.JSON;
import static com.base.common.GlobaConstants.MSG;
import static com.base.common.GlobaConstants.ROOT;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.base.common.bean.ActionResult;
import com.cjy.common.bean.OpAttributes;

/**
 * 获取当前登陆用户权限信息
 * 
 * @author John 时间：2014.09.22
 */
@Action("checkAuthorityAction")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
		ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_HTML }) })
public class CheckAuthorityActionUtil extends AbstractBaseAction {
	private String user_id;// 当前登陆用户ID
	private String auth_str;// 权限字符串
	private String msg;// 返回到前台的信息

	public String getUser_id() {
		return user_id;
	}

	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}

	public String getAuth_str() {
		return auth_str;
	}

	public void setAuth_str(String auth_str) {
		this.auth_str = auth_str;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String checkAuthority() {
		System.out.println("开始检测用户权限");
		Subject currentUser = SecurityUtils.getSubject();
		// 判断是否有这个权限
		if (currentUser.isPermitted(auth_str)) {
			actionResult = ActionResult.getActionResult(new OpAttributes(MSG,
					"repeat"));
		} else {
			actionResult = ActionResult.getActionResult(new OpAttributes(MSG,
					""));
		}
		return returnType();
	}

}
